//
//  RegisterVarficationCode.m
//  XJMTechnician
//
//  Created by Mr.hu on 2017/10/18.
//  Copyright © 2017年 Mr.hu. All rights reserved.
//

#import "PaySecretFirst.h"
#import "RegisterSucces.h"

@interface PaySecretFirst ()<WLUnitFieldDelegate>
{
    CGFloat addCode;
}

@property (weak, nonatomic) IBOutlet WLUnitField *UnitFieldInput;

@property (weak, nonatomic) IBOutlet WLUnitField *UnitFieldSub;

@property (weak, nonatomic) IBOutlet UIButton *PayCompletySubmit;

@property (nonatomic,strong) NSString *codeStr; //first
@property (nonatomic,copy) NSString * Code_secondstr;

@property (weak, nonatomic) IBOutlet UILabel *FirstCircleLab;
@property (weak, nonatomic) IBOutlet UILabel *SecondCircleLab;

@end

@implementation PaySecretFirst

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addLeftBtn:[UIImage imageNamed:@"fanhui"] Action:@selector(backToPrevious)];
    self.title = @"支付密码";
    self.UnitFieldInput.delegate = self;
    [_UnitFieldInput addTarget:self action:@selector(unitFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
    
    self.UnitFieldInput.unitSpace = 12;
    self.UnitFieldInput.borderRadius = 4;
    [self.UnitFieldInput sizeToFit];
    
    
    self.UnitFieldSub.delegate = self;
    [self.UnitFieldSub addTarget:self action:@selector(SubUnitFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
    self.UnitFieldSub.unitSpace = 12;
    self.UnitFieldSub.borderRadius = 4;
    [self.UnitFieldSub sizeToFit];
    
    addCode = 0;
    
    self.PayCompletySubmit.layer.cornerRadius =20;
    self.FirstCircleLab.layer.cornerRadius = 4;
    self.FirstCircleLab.layer.masksToBounds = YES;
    self.SecondCircleLab.layer.cornerRadius = 4;
    self.SecondCircleLab.layer.masksToBounds = YES;
    
}

- (void)unitFieldEditingChanged:(WLUnitField*)sender{
    
    self.codeStr = [NSString stringWithFormat:@"%@",sender.text];
    
}

- (void)SubUnitFieldEditingChanged:(WLUnitField*)sender{
    
    self.Code_secondstr = [NSString stringWithFormat:@"%@",sender.text];
    
}


- (BOOL)unitField:(WLUnitField *)uniField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    
    if (self.UnitFieldSub) {
     
    // 判断是不是“删除”字符
    if (string.length != 0) { // 不是“删除”字符
//        self.codeStr = [uniField.text stringByAppendingString:string];
    } else { // 是“删除”字符
//        self.codeStr = [uniField.text substringToIndex:uniField.text.length - 1];
        }
    }
    NSLog(@"");
    
    addCode++;
    
    if (addCode == 6) {
        
    }
    
    return YES;
}

- (IBAction)SetSecretSuccessMeth:(id)sender {
    
    if ([self.codeStr isEqualToString:self.Code_secondstr]) {
        
        [XJHttpClass teachRegisterThreePayPwd:self.codeStr re_paypwd:self.Code_secondstr andFinishblock:^(id response, NSString *errStr) {
            
            if (errStr) {
                [XJToolClass tipAnimationWith:errStr];
            }else{
                
                RegisterSucces * setting = [[RegisterSucces alloc]init];
                setting.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:setting animated:YES];
            }
        }];
    }else{
        
        [XJToolClass tipAnimationWith:@"密码输入错误,请重新输入！"];
    }
}

@end
